package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.AuctionFavorite;
import com.ruoyi.demo.service.IAuctionFavoriteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 收藏Controller
 *
 * @author metaee
 * @date 2025-02-24
 */
@Api(tags = "收藏管理")
@RestController
@RequestMapping("/demo/favorite")
public class AuctionFavoriteController extends BaseController
{
    @Autowired
    private IAuctionFavoriteService auctionFavoriteService;

    /**
     * 查询收藏列表
     */
    @ApiOperation("查询收藏列表")
    @GetMapping("/list")
    public TableDataInfo list(AuctionFavorite auctionFavorite)
    {
        startPage();
        List<AuctionFavorite> list = auctionFavoriteService.selectAuctionFavoriteList(auctionFavorite);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @ApiOperation("导出收藏列表")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionFavorite auctionFavorite)
    {
        List<AuctionFavorite> list = auctionFavoriteService.selectAuctionFavoriteList(auctionFavorite);
        ExcelUtil<AuctionFavorite> util = new ExcelUtil<AuctionFavorite>(AuctionFavorite.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @ApiOperation("获取收藏详细信息")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(auctionFavoriteService.selectAuctionFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增收藏
     */
    @ApiOperation("新增收藏")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionFavorite auctionFavorite)
    {
        return toAjax(auctionFavoriteService.insertAuctionFavorite(auctionFavorite));
    }

    /**
     * 修改收藏
     */
    @ApiOperation("修改收藏")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionFavorite auctionFavorite)
    {
        return toAjax(auctionFavoriteService.updateAuctionFavorite(auctionFavorite));
    }

    /**
     * 删除收藏
     */
    @ApiOperation("删除收藏")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(auctionFavoriteService.deleteAuctionFavoriteByFavoriteIds(favoriteIds));
    }
}
